
var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: ["代订单", "进行中", "已付款"],
    activeIndex: 0,
    sliderOffset: 0,
    sliderLeft: 0,
    isShow: false,//  false 展示小内容   true 展示全
    phoneIsShow: true, //true 隐藏  flase 显示
    cardIsShow: true, //true 隐藏  flase 显示
    phoneNumber: "",
    dataArray: [{ isShow: false, title: "你时谁1" },
    { isShow: false, title: "你时谁1" },
    { isShow: false, title: "你时谁1" },
    { isShow: false, title: "你时谁1" },
    { isShow: false, title: "你时谁1" }],
    dataArrayTwo: [{ isShow: true, title: "你时谁2", phoneNumber: "15010460727" },
    { isShow: false, title: "你时谁2", phoneNumber: "322323" },
    { isShow: false, title: "你时谁2", phoneNumber: "1501044547" },
    { isShow: false, title: "你时谁2", phoneNumber: "454545" },
    { isShow: false, title: "你时谁2", phoneNumber: "454545" }],
    dataArrayThree: [{ isShow: true, title: "你时谁3", phoneNumber: "" },
    { isShow: false, title: "你时谁3", phoneNumber: "" },
    { isShow: false, title: "你时谁3", phoneNumber: "" },
    { isShow: false, title: "你时谁3", phoneNumber: "" },
    { isShow: false, title: "你时谁3", phoneNumber: "" }],
    photoList: ["https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1526968905&di=512c9c22bc114f83ef422a280962791e&src=http://img6.ph.126.net/UhuHnk81yx4KusWh9v2qkQ==/6597910893051913176.jpg", "https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1526968905&di=512c9c22bc114f83ef422a280962791e&src=http://img6.ph.126.net/UhuHnk81yx4KusWh9v2qkQ==/6597910893051913176.jpg", "https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1526968905&di=512c9c22bc114f83ef422a280962791e&src=http://img6.ph.126.net/UhuHnk81yx4KusWh9v2qkQ==/6597910893051913176.jpg", "https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1526968905&di=512c9c22bc114f83ef422a280962791e&src=http://img6.ph.126.net/UhuHnk81yx4KusWh9v2qkQ==/6597910893051913176.jpg", "https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1526968905&di=512c9c22bc114f83ef422a280962791e&src=http://img6.ph.126.net/UhuHnk81yx4KusWh9v2qkQ==/6597910893051913176.jpg", "https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1526968905&di=512c9c22bc114f83ef422a280962791e&src=http://img6.ph.126.net/UhuHnk81yx4KusWh9v2qkQ==/6597910893051913176.jpg",]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
          sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
        });
      }
    });

  },

  tabClick: function (e) {
    this.setData({
      sliderOffset: e.currentTarget.offsetLeft,
      activeIndex: e.currentTarget.id
    });
  },
  // 点击展示页面
  orderShow: function (re) {
    var that = this;
    var yesShow = "dataArray[" + re.currentTarget.dataset.index + "].isShow";
    for (var i = 0; i < that.data.dataArray.length; i++) {
      // 点击的item 布尔值为ture 展示
      if (i == re.currentTarget.dataset.index) {
        that.setData({
          [yesShow]: true
        })
      } else {
        // 未点击的  false 取消展示
        var noShow = "dataArray[" + i + "].isShow";
        that.setData({
          [noShow]: false
        })
      }
    }

  },
  // 点击隐藏
  orderHide: function (re) {
    var that = this;
    var yesShow = "dataArray[" + re.currentTarget.dataset.index + "].isShow";
    for (var i = 0; i < that.data.dataArray.length; i++) {
      // 点击的item 布尔值为ture 展示
      if (i == re.currentTarget.dataset.index) {
        that.setData({
          [yesShow]: false
        })
      } else {
        // 未点击的  false 取消展示
        var noShow = "dataArray[" + i + "].isShow";
        that.setData({
          [noShow]: false
        })
      }
    }

  },
  // 第二个模块
  orderShowTwo: function (re) {
    var that = this;
    var yesShow = "dataArrayTwo[" + re.currentTarget.dataset.index + "].isShow";
    for (var i = 0; i < that.data.dataArrayTwo.length; i++) {
      // 点击的item 布尔值为ture 展示
      if (i == re.currentTarget.dataset.index) {
        that.setData({
          [yesShow]: true
        })
      } else {
        // 未点击的  false 取消展示
        var noShow = "dataArrayTwo[" + i + "].isShow";
        that.setData({
          [noShow]: false
        })
      }
    }

  },
  // 第二个模块点击隐藏
  orderHideTwo: function (re) {
    var that = this;
    var yesShow = "dataArrayTwo[" + re.currentTarget.dataset.index + "].isShow";
    for (var i = 0; i < that.data.dataArrayTwo.length; i++) {
      // 点击的item 布尔值为ture 展示
      if (i == re.currentTarget.dataset.index) {
        that.setData({
          [yesShow]: false
        })
      } else {
        // 未点击的  false 取消展示
        var noShow = "dataArrayTwo[" + i + "].isShow";
        that.setData({
          [noShow]: false
        })
      }
    }

  },
  // 第三个模块
  orderShowThree: function (re) {
    var that = this;
    var yesShow = "dataArrayThree[" + re.currentTarget.dataset.index + "].isShow";
    for (var i = 0; i < that.data.dataArrayThree.length; i++) {
      // 点击的item 布尔值为ture 展示
      if (i == re.currentTarget.dataset.index) {
        that.setData({
          [yesShow]: true
        })
      } else {
        // 未点击的  false 取消展示
        var noShow = "dataArrayThree[" + i + "].isShow";
        that.setData({
          [noShow]: false
        })
      }
    }

  },
  // 第二个模块点击隐藏
  orderHideThree: function (re) {
    var that = this;
    var yesShow = "dataArrayThree[" + re.currentTarget.dataset.index + "].isShow";
    for (var i = 0; i < that.data.dataArrayThree.length; i++) {
      // 点击的item 布尔值为ture 展示
      if (i == re.currentTarget.dataset.index) {
        that.setData({
          [yesShow]: false
        })
      } else {
        // 未点击的  false 取消展示
        var noShow = "dataArrayThree[" + i + "].isShow";
        that.setData({
          [noShow]: false
        })
      }
    }

  },
  // 复制
  bindCopy: function (re) {

    wx.setClipboardData({
      data: re.target.dataset.text,
      success: function () {
        wx.showToast({
          title: '复制成功',
        })

      }
    })
  },
  // 手机拨打
  bindPhone: function (re) {

    var that = this;
    // 进行中的点击
    if (re.currentTarget.dataset.replyType == "new") {

      if (that.data.dataArrayTwo[re.currentTarget.dataset.index].phoneNumber == "") {
        that.setData({
          phoneIsShow: false,
          phoneNumber: "未知"
        })
      } else {
        that.setData({
          phoneIsShow: false,
          phoneNumber: that.data.dataArrayTwo[re.currentTarget.dataset.index].phoneNumber
        })
      }

      // 已付款的点击
    } else if (re.currentTarget.dataset.replyType == "old") {
      if (that.data.dataArrayThree[re.currentTarget.dataset.index].phoneNumber == "") {
        that.setData({
          phoneIsShow: false,
          phoneNumber: "未知"
        })
      } else {
        that.setData({
          phoneIsShow: false,
          phoneNumber: that.data.dataArrayThree[re.currentTarget.dataset.index].phoneNumber
        })
      }
    }

  },
  //取消手机拨打
  noPhoneRemind: function (re) {

    var that = this;
    // 关闭 信息卡片
    if (re.target.dataset.replyType == "card") {

      that.setData({
        cardIsShow: true,
      })
      // 关闭 手机卡片
    } else if (re.target.dataset.replyType == "phone") {

      that.setData({
        phoneIsShow: true,
        phoneNumber: ""
      })
    }

  },
  // 第二个页面 用户信息卡片
  bindcardMessage: function (re) {
    var that = this;
    that.setData({
      cardIsShow: false,
    })
  },
  scanCode: function (re) {
    wx.scanCode({
      success: (re) => {
        wx.showToast({
          title: '扫描成功',
          icon: 'success',
          duration: 2000
        })
      },
      fail: (re) => {
        wx.showToast({
          title: '扫描失败',
          icon: 'success',
          duration: 2000
        })
      }
    })
  },
  // 防止弹框滑动
  noMove: function (re) {

  },
  onShareAppMessage: function () {

  }
})